import React, {useEffect, useState} from 'react';
import {View, Text, Image, TouchableOpacity, TextInput} from 'react-native';
import {useNavigation} from '@react-navigation/native';
import AreaView from '../../components/Layout/AreaView';
import {getProtocol} from '../../service/login';
import {WebView} from 'react-native-webview';

const Protocol = (props) => {
  const {
    route: {
      params: {pid},
    },
  } = props;

  const navigation = useNavigation();
  const [content, setContent] = useState('');

  useEffect(() => {
    navigation.setOptions({
      title: '协议',
    });

    getProtocol(pid).then((res) => {
      console.log(res, 'content');
      setContent(res.data.content);
    });
  }, [navigation]);

  return (
    <AreaView>
      <WebView
        useWebKit={true}
        originWhitelist={['*']}
        source={{
          html:
            '<html><head><meta name="viewport" content="width=device-width, initial-scale=0.7"></head><body>' +
            content +
            '</body></html>',
        }}
      />
    </AreaView>
  );
};

export default Protocol;
